package com.zxu.test.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.Observable;
import androidx.lifecycle.ViewModelProviders;

import com.zxu.test.base.BaseFragment;
import com.zxu.test.studyapp.databinding.ActivityActionBinding;
import com.zxu.test.util.Event;
import com.zxu.test.util.IntentMsg;
import com.zxu.test.util.StrUtil;

public class ActionFragment extends BaseFragment {
    private ActivityActionBinding mBinding;
    private ActionViewModel mViewModel;
    public ActionFragment() { }
    public static ActionFragment getInstance() {
        return new ActionFragment();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding = ActivityActionBinding.inflate(inflater, container, false);
        mViewModel = ViewModelProviders.of(getActivity()).get(ActionViewModel.class);
        mBinding.setViewModel(mViewModel);
        IntentMsg intentMsg = (IntentMsg) getActivity().getIntent().getSerializableExtra(IntentMsg.MSG);
        switch (intentMsg.Action_Msg){
            case StrUtil.ACTIONACTIVITY_ACTION:
                mViewModel.tv_ac.set(StrUtil.ACTIONACTIVITY_ACTION);
                break;
        }
        return  mBinding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        setupListener();
    }

    private void setupListener() {
        mViewModel.getBroadcastCommand().observe(getViewLifecycleOwner(), this::goToSendBrodcast);
        mViewModel.btnEvent.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
            @Override
            public void onPropertyChanged(Observable sender, int propertyId) {

            }
        });
        mViewModel.rxEvent.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
            @Override
            public void onPropertyChanged(Observable sender, int propertyId) {
            }
        });
        mViewModel.cancelEvent.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
            @Override
            public void onPropertyChanged(Observable sender, int propertyId) {
            }
        });
        mViewModel.saveEvent.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
            @Override
            public void onPropertyChanged(Observable sender, int propertyId) {
            }
        });
    }

    private void goToSendBrodcast(Event<Object> taskIdEvent) {

    }
}
